package demo1;

import java.util.Arrays;

public class Test {

    public static void bubbleSort(Comparable[] comparables){
        for (int i = 0; i < comparables.length - 1; i++) {
            for (int j = 0; j < comparables.length - 1 - i; j++) {
                if(comparables[j].compareTo(comparables[j+1]) > 0){
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j+1];
                    comparables[j+1] = tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Student[] students = new Student[4];
        students[0] = new Student("xiaoge",20,78.4);
        students[1] = new Student("wangpangzi",18,90);
        students[2] = new Student("wuxie",19,65.52);
        students[3] = new Student("panzi",30,70);

        bubbleSort(students);

        System.out.println(Arrays.toString(students));
    }
    public static void main2(String[] args) {
        Student[] student = new Student[3];
        student[0] = new Student("zhangsan",20,78.4);
        student[1] = new Student("lisi",18,90);
        student[2] = new Student("wangwu",19,65.52);

        ScoreComparator scoreComparator = new ScoreComparator();
        AgeComparator ageComparator = new AgeComparator();

        Arrays.sort(student,scoreComparator);
        Arrays.sort(student,ageComparator);

        System.out.println(Arrays.toString(student));
    }


    public static void main1(String[] args) {
        Student student1 = new Student("zhangsan",24,78.3);
        Student student2 = new Student("lisi",20,88.88);

        //使用比较器需要类的引用
        NameComparator nameComparator = new NameComparator();
        if(nameComparator.compare(student1,student2) > 0){
            System.out.println("姓名比较：student1 > student2");
        }else{
            System.out.println("姓名比较：student1 < student2");
        }

        System.out.println("-----------");

        AgeComparator ageComparator = new AgeComparator();
        if(ageComparator.compare(student1,student2) > 0) {
            System.out.println("年龄比较：student1 > student2");
        }else{
            System.out.println("年龄比较：student1 < student2");
        }

        System.out.println("-----------");

        ScoreComparator scoreComparator = new ScoreComparator();

        if(scoreComparator.compare(student1,student2) > 0){
            System.out.println("成绩比较：student1 > student2");
        }else{
            System.out.println("成绩比较：student1 < student2");
        }

        System.out.println("-----------");

        if(student1.compareTo(student2) > 0){
            System.out.println("student1 > student2");
        }else{
            System.out.println("student1 < student2");
        }

     /*   if(student1.age > student2.age){
            System.out.println("student1 > student2");
        }else{
            System.out.println("student1 < student2");
        }*/

    }

}
